/**
 * 
 */
package ae.pcfc.cldos.online.web.controller.client.company.ev.renewal;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import ae.pcfc.cldos.online.common.ConstantsCommon.Steps;
import ae.pcfc.cldos.online.common.delegate.EmploymentVisaRenewalDelegate;
import ae.pcfc.cldos.online.common.vo.FileVO;
import ae.pcfc.cldos.online.common.vo.ev.ren.can.EmploymentVisaRenewalVO;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.ViewUtils;
import ae.pcfc.cldos.online.web.controller.base.BasePageController;
import ae.pcfc.cldos.online.web.model.EVRenewalModel;

/**
 * 
 * @author Asna
 *
 */
@Controller
@RequestMapping(value = ViewPath.__ADMIN_EMPLOYMENT_VISA_RENEWAL_VIEW)
public class EVRenewalViewController extends BasePageController{
	
	@Autowired
	@Qualifier("employmentVisaRenewalDelegate")
	private EmploymentVisaRenewalDelegate employmentVisaRenewalDelegate;
	

	
	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model, @RequestParam String appId) {
		breadCrumbsFactoryService.populateallAppReqDtlBreadCrumb(model);
	}
	
	@ModelAttribute("evRenewalModel")
	public EVRenewalModel populateRegisterEmploymentVisaReviewerInfoModel(@RequestParam String appId,
			HttpServletRequest request, ModelMap model) throws Exception {
		EVRenewalModel evRenewalModel = new EVRenewalModel();
		
		EmploymentVisaRenewalVO employmentVisaRenewalVO = 
				employmentVisaRenewalDelegate.getEmploymentVisaRenewalAppInfo(
						encryptionDelegate.decodeAndDecrypt(appId), getUserVO(), Steps.ALL_APP_REQUEST);
		
		List<FileVO> fileVOList = employmentVisaRenewalVO.getFileVOList();
		model.put("files", fileVOList);
		model.put("comments", employmentVisaRenewalVO.getApplicationCommentVOs());
		
		mapper.map(employmentVisaRenewalVO.getEmploymentVisaRenewalDetailsVO(), evRenewalModel);
		evRenewalModel.setWfStatus(employmentVisaRenewalVO.getWfStatus());
		model.put("appId", appId);
		return evRenewalModel;
	}
	

	
	@RequestMapping(value = "/form.htm", method = RequestMethod.GET)
	public ModelAndView form() {
		return ViewUtils.DEFAULT_VIEW;
	}
	

	
}
